//
//  VCOfSetting.m
//  LCOnePsychology
//
//  Created by li cheng on 16/9/19.
//  Copyright © 2016年 li cheng. All rights reserved.
//

#import "VCOfSetting.h"
#import "BaseTableView.h"
#import "MJMacro.h"
@interface VCOfSetting ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) NSArray *arrayOfName;
@end

@implementation VCOfSetting

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    //
    _arrayOfName = @[@"夜间模式", @"分享给好友", @"版本信息", @"退出登录"];
    // navigation 左边的button
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"< 返回" style:UIBarButtonItemStylePlain target:self action:@selector(back:)];
    // 创建 tabelView
    [self createTableView];
}
#pragma mark - 返回的的实现
- (void)back:(UIBarButtonItem *)barButtonItem{
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}
#pragma mark - 创建 tableView
- (void)createTableView{
    BaseTableView *tableViewOfUserProfile = [[BaseTableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 64) style:UITableViewStylePlain];
    tableViewOfUserProfile.bounces = NO;
    tableViewOfUserProfile.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    [self.view addSubview:tableViewOfUserProfile];
    tableViewOfUserProfile.delegate = self;
    tableViewOfUserProfile.dataSource = self;
    [tableViewOfUserProfile registerClass:[UITableViewCell class] forCellReuseIdentifier:@"UITableViewCell"];
}
#pragma mark - tableView 协议方法 row 数量的确定
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString *user_id = [user objectForKey:@"user_id"];
    if (user_id) {
        return 4;
    } else {
        return 3;
    }
}
#pragma mark - tableView 代理方法 cell 的赋值
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell" forIndexPath:indexPath];
    cell.textLabel.text = _arrayOfName[indexPath.row];
    return cell;
}
#pragma mark - 点击退出登录
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row == 3) {
        NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
        [user removeObjectForKey:@"avatar"];
        [user removeObjectForKey:@"dataId"];
        [user removeObjectForKey:@"nickname"];
        [user removeObjectForKey:@"baseId"];
        [user removeObjectForKey:@"user_id"];
        [user synchronize];
        [self dismissViewControllerAnimated:YES completion:^{
            
        }];
    } else {
        [self pleaseWait];
    }
}
#pragma mark - 还未开放此功能
- (void)pleaseWait{
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"这个功能目前还没有开放" message:@"你可以尝试别的东西" preferredStyle:UIAlertControllerStyleActionSheet];
    [alertController addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
    }]];
    [self presentViewController:alertController animated:YES completion:^{
        
    }];
}
#pragma mark - 其他, 内存警告
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
